const upwardModel = require("../../../model/upwards");
const sipUtils = require("../../../utils/sipUtils");

const TAG = "[clientUtils]";
module.exports = {
    /**
     * 构造向上级连的上级uri
     * @return {Promise<{self_account: ([{trigger: string, message: string, required: boolean}]|string|*), upwardUri: string}>}
     */
    async generateClientParams() {
        const upwards = await upwardModel.load();
        const upward = upwards[0];
        const upwardUri = sipUtils.generateUri(upwards[0].upper_account, null, null, upwards[0].upper_host, upwards[0].upper_port);
        const selfUri = "sip:" + upward.self_account + "@" + upward.upper_realm
        // console.info(TAG, '上级',  upward,'selfUri', selfUri, 'upwardUri', upwardUri);
        return {
            upward,
            upwardUri,
            selfUri,
            self_account: upward.self_account
        };
    }
}
